﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using EShop.Common;
using EShop.BLL;
using DateConvert;

namespace EShop.Client
{
    public partial class frmRemindBrithday : Form
    {
        DateConvert.DateConvert oDateConvert = new DateConvert.DateConvert();
        
        public frmRemindBrithday()
        {
            InitializeComponent();
        }

        private void frmRemindBrithday_Load(object sender, EventArgs e)
        {
            string msg = string.Empty;
            msg = "今天是公历:" + DateTime.Now.ToString("yyyy年MM月dd日") + "    |   农历:" + oDateConvert.GetLunarCalendar(DateTime.Now);
            lblMsg.Text = msg;
            BindMember();
            BindEmployee();
        }

        private void BindMember()
        {
            MemberManagerBLL oMemberManagerBLL = new MemberManagerBLL();
            DataTable dt = oMemberManagerBLL.GetMember(null, 0);
            dgvMember.Rows.Clear();
            int index = -1;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bool isShow = false;
                string brithday = Convert.ToDateTime(dt.Rows[i]["Brithday"]).ToString("MM-dd");
                bool IsGregorianCalendar = Convert.ToBoolean(dt.Rows[i]["IsGregorianCalendar"]);
                if (IsGregorianCalendar && brithday.Equals(DateTime.Now.ToString("MM-dd")))
                {
                    isShow = true;
                }
                if (IsGregorianCalendar == false && brithday.Equals(oDateConvert.GetLunarCalendarDateTime(DateTime.Now).ToString("MM-dd")))
                {
                    isShow = true;
                }
                if (isShow)
                {
                    index = dgvMember.Rows.Add();
                    dgvMember.Rows[index].Cells["MemberID"].Value = dt.Rows[i]["MemberID"];
                    dgvMember.Rows[index].Cells["MemberName"].Value = dt.Rows[i]["MemberName"];
                    dgvMember.Rows[index].Cells["MemberSex"].Value = Convert.ToInt32(dt.Rows[i]["MemberSex"]) == 1 ? "女" : "男";
                    dgvMember.Rows[index].Cells["IsGregorianCalendar"].Value = IsGregorianCalendar ? "公历" : "农历";
                    dgvMember.Rows[index].Cells["Brithday"].Value = brithday;
                    dgvMember.Rows[index].Cells["Mobile"].Value = dt.Rows[i]["MemberMobel"];
                    dgvMember.Rows[index].Cells["LevelName"].Value = dt.Rows[i]["LevelName"];
                    dgvMember.Rows[index].Cells["CreateTime"].Value = dt.Rows[i]["CreateTime"];
                }
            }
        }
        private void BindEmployee()
        {
            EmployeeBLL oEmployeeBLL = new EmployeeBLL();
            DataTable dt = oEmployeeBLL.QueryEmployeeInfo(null);
            dgvEmployee.Rows.Clear();
            int index = -1;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                bool isShow = false;
                string brithday = Convert.ToDateTime(dt.Rows[i]["Brithday"]).ToString("MM-dd");
                bool IsGregorianCalendar = Convert.ToBoolean(dt.Rows[i]["IsGregorianCalendar"]);
                if (IsGregorianCalendar && brithday.Equals(DateTime.Now.ToString("MM-dd")))
                {
                    isShow = true;
                }
                if (IsGregorianCalendar == false && brithday.Equals(oDateConvert.GetLunarCalendarDateTime(DateTime.Now).ToString("MM-dd")))
                {
                    isShow = true;
                }
                if (isShow)
                {
                    index = dgvEmployee.Rows.Add();
                    dgvEmployee.Rows[index].Cells["EmployeeID"].Value = dt.Rows[i]["EmployeeID"];
                    dgvEmployee.Rows[index].Cells["FullName"].Value = dt.Rows[i]["FullName"];
                    dgvEmployee.Rows[index].Cells["Sex"].Value = Convert.ToInt32(dt.Rows[i]["Sex"]) == 1 ? "女" : "男";
                    dgvEmployee.Rows[index].Cells["EmployeeIsGregorianCalendar"].Value = IsGregorianCalendar ? "公历" : "农历";
                    dgvEmployee.Rows[index].Cells["EmployeeBrithday"].Value = brithday;
                    dgvEmployee.Rows[index].Cells["EmployeeMobile"].Value = dt.Rows[i]["Mobile"];
                    dgvEmployee.Rows[index].Cells["LastLoginTime"].Value = dt.Rows[i]["LastLoginDatetime"];
                    dgvEmployee.Rows[index].Cells["EmployeeCreateTime"].Value = dt.Rows[i]["CreateDatetime"];
                }
            }
        
        }
    }
}
